home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP10 / POORMENU.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  3.0 KB  |  92 lines

  1. /*-----------------------------------------
  2.    POORMENU.C -- The Poor Person's Menu
  3.                  (c) Charles Petzold, 1996
  4.   -----------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. #define IDM_ABOUT   1
  9. #define IDM_HELP    2
  10. #define IDM_REMOVE  3
  11.  
  12. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  13.  
  14. static char szAppName[] = "PoorMenu" ;
  15.  
  16. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  17.                     PSTR szCmdLine, int iCmdShow)
  18.      {
  19.      HMENU      hMenu ;
  20.      HWND       hwnd ;
  21.      MSG        msg ;
  22.      WNDCLASSEX wndclass ;
  23.  
  24.      wndclass.cbSize        = sizeof (wndclass) ;
  25.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  26.      wndclass.lpfnWndProc   = WndProc ;
  27.      wndclass.cbClsExtra    = 0 ;
  28.      wndclass.cbWndExtra    = 0 ;
  29.      wndclass.hInstance     = hInstance ;
  30.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  31.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  32.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  33.      wndclass.lpszMenuName  = NULL ;
  34.      wndclass.lpszClassName = szAppName ;
  35.      wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;
  36.  
  37.      RegisterClassEx (&wndclass) ;
  38.  
  39.      hwnd = CreateWindow (szAppName, "The Poor-Person's Menu",
  40.                           WS_OVERLAPPEDWINDOW,
  41.                           CW_USEDEFAULT, CW_USEDEFAULT,
  42.                           CW_USEDEFAULT, CW_USEDEFAULT,
  43.                           NULL, NULL, hInstance, NULL) ;
  44.  
  45.      hMenu = GetSystemMenu (hwnd, FALSE) ;
  46.  
  47.      AppendMenu (hMenu, MF_SEPARATOR, 0,          NULL) ;
  48.      AppendMenu (hMenu, MF_STRING,    IDM_ABOUT,  "About...") ;
  49.      AppendMenu (hMenu, MF_STRING,    IDM_HELP,   "Help...") ;
  50.      AppendMenu (hMenu, MF_STRING,    IDM_REMOVE, "Remove Additions") ;
  51.  
  52.      ShowWindow (hwnd, iCmdShow) ;
  53.      UpdateWindow (hwnd) ;
  54.  
  55.      while (GetMessage (&msg, NULL, 0, 0))
  56.           {
  57.           TranslateMessage (&msg) ;
  58.           DispatchMessage (&msg) ;
  59.           }
  60.      return msg.wParam ;
  61.      }
  62.  
  63. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  64.      {
  65.      switch (iMsg)
  66.           {
  67.           case WM_SYSCOMMAND :
  68.                switch (LOWORD (wParam))
  69.                     {
  70.                     case IDM_ABOUT :
  71.                          MessageBox (hwnd, "A Poor-Person's Menu Program.",
  72.                                      szAppName, MB_OK | MB_ICONINFORMATION) ;
  73.                          return 0 ;
  74.  
  75.                     case IDM_HELP :
  76.                          MessageBox (hwnd, "Help not yet implemented!",
  77.                                      szAppName, MB_OK | MB_ICONEXCLAMATION) ;
  78.                          return 0 ;
  79.  
  80.                     case IDM_REMOVE :
  81.                          GetSystemMenu (hwnd, TRUE) ;
  82.                          return 0 ;
  83.                     }
  84.                break ;
  85.  
  86.           case WM_DESTROY :
  87.                PostQuitMessage (0) ;
  88.                return 0 ;
  89.           }
  90.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  91.      }
  92.